package com.ruoyi.labdata.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.labdata.mapper.LabBlacklistPersonnelMapper;
import com.ruoyi.labdata.domain.LabBlacklistPersonnel;
import com.ruoyi.labdata.domain.LabFile;
import com.ruoyi.labdata.service.ILabBlacklistPersonnelService;
import com.ruoyi.labdata.service.ILabFileService;
import com.ruoyi.system.utils.FileTypeEnum;

/**
 * 实验室黑名单人员Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-04-02
 */
@Service
public class LabBlacklistPersonnelServiceImpl implements ILabBlacklistPersonnelService {
	@Autowired
	private LabBlacklistPersonnelMapper labBlacklistPersonnelMapper;
	@Autowired
    private ILabFileService labFileService;
	
	private static final String belongType = FileTypeEnum.UserBlack.getValue();

	/**
	 * 查询实验室黑名单人员
	 * 
	 * @param id
	 *            实验室黑名单人员ID
	 * @return 实验室黑名单人员
	 */
	@Override
	public LabBlacklistPersonnel selectLabBlacklistPersonnelById(Long id) {
		List<LabFile> labFiles = labFileService.getFiles(id, belongType);
		LabBlacklistPersonnel userBlack =  labBlacklistPersonnelMapper.selectLabBlacklistPersonnelById(id);
		userBlack.setImages(labFiles);
		return userBlack;
	}

	/**
	 * 查询实验室黑名单人员列表
	 * 
	 * @param labBlacklistPersonnel
	 *            实验室黑名单人员
	 * @return 实验室黑名单人员
	 */
	@Override
	public List<LabBlacklistPersonnel> selectLabBlacklistPersonnelList(LabBlacklistPersonnel labBlacklistPersonnel) {
		return labBlacklistPersonnelMapper.selectLabBlacklistPersonnelList(labBlacklistPersonnel);
	}

	/**
	 * 新增实验室黑名单人员
	 * 
	 * @param labBlacklistPersonnel
	 *            实验室黑名单人员
	 * @return 结果
	 */
	@Override
	public int insertLabBlacklistPersonnel(LabBlacklistPersonnel labBlacklistPersonnel) {
		labBlacklistPersonnel.setCreateTime(DateUtils.getNowDate());
		return labBlacklistPersonnelMapper.insertLabBlacklistPersonnel(labBlacklistPersonnel);
	}

	/**
	 * 修改实验室黑名单人员
	 * 
	 * @param labBlacklistPersonnel
	 *            实验室黑名单人员
	 * @return 结果
	 */
	@Override
	@Transactional
	public int updateLabBlacklistPersonnel(LabBlacklistPersonnel labBlacklistPersonnel) {
		labFileService.updateFiles(labBlacklistPersonnel.getImages(), 
				labBlacklistPersonnel.getId(), belongType);
		labBlacklistPersonnel.setIsRemove(1);
		labBlacklistPersonnel.setRemoveByNo(SecurityUtils.getUsername());
		labBlacklistPersonnel.setRemoveUserName(SecurityUtils.getNickName());
		return labBlacklistPersonnelMapper.updateLabBlacklistPersonnel(labBlacklistPersonnel);
	}

	/**
	 * 批量删除实验室黑名单人员
	 * 
	 * @param ids
	 *            需要删除的实验室黑名单人员ID
	 * @return 结果
	 */
	@Override
	public int deleteLabBlacklistPersonnelByIds(Long[] ids) {
		return labBlacklistPersonnelMapper.deleteLabBlacklistPersonnelByIds(ids);
	}

	/**
	 * 删除实验室黑名单人员信息
	 * 
	 * @param id
	 *            实验室黑名单人员ID
	 * @return 结果
	 */
	@Override
	public int deleteLabBlacklistPersonnelById(Long id) {
		return labBlacklistPersonnelMapper.deleteLabBlacklistPersonnelById(id);
	}
}
